package xyz.funnygo.fragment;

import xyz.funnygo.activity.LoginActivity;
import xyz.funnygo.activity.MyInfoActivity;
import xyz.funnygo.activity.R;
import xyz.funnygo.base.BaseFragment;
import xyz.funnygo.model.User;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 已登录后我的信息页面
 * @author stg_win10
 *
 */
public class MyInfoFragment extends BaseFragment
		implements OnClickListener{

	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_me_in, null);
        initView(view);
        return view;
    }

	@Override
	public void initView(View view) {
		TextView nameView = (TextView) view.findViewById(R.id.me_name);
		nameView.setText(User.getCurrentUser(getActivity(), User.class).getUsername());
		Button logout = (Button) view.findViewById(R.id.me_btn_logout);
		logout.setOnClickListener(this);
		ImageView myInfo = (ImageView) view.findViewById(R.id.me_name_right);
		myInfo.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.me_setting:
			
			break;
		case R.id.me_name_right:
			startActivity(new Intent(getActivity(), MyInfoActivity.class));
			break;
		case R.id.me_btn_logout:
			User.logOut(getActivity().getApplicationContext());
			startActivity(new Intent(getActivity(), LoginActivity.class));
			break;
		default:
			break;
		}
		
	}
	
}
